﻿using System;
using System.IO;
using System.Data.SqlClient;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

using LMSemir.Common;
using LMSemir.Entity;
namespace LMSemir.DAC
{
    public class TeeDataAccess
    {
        private TeeDataAccess() { }

        //数据库连接字符串
        public static string ConnString { get; set; }

        /// <summary>
        /// 根据作品分类ID、作品ID，返回相近的50个ID列表.
        /// </summary>
        /// <param name="teeID"></param>
        /// <param name="categoryID"></param>
        /// <returns></returns>
        public static DataTable getTeeIdList(int teeID, int categoryID)
        {
            DataTable dt = new DataTable();
            StringBuilder strSelect = new StringBuilder();
            strSelect.AppendFormat("select tid from v_teeinfo where tstatus=4 ");
            if (categoryID > 1)
            {
                strSelect.AppendFormat(" and tcid={0}", categoryID);
            }
            strSelect.AppendFormat(" and tid between ");
            int startID = 0;
            if (teeID - 50 < 0)
            {
                startID = 0;
            }
            strSelect.AppendFormat("'{0}' ", startID);
            strSelect.AppendFormat("and ");
            strSelect.AppendFormat("'{0}' ", teeID + 50);

            if (categoryID == 1)
            {
                strSelect.AppendFormat(" order by TAVoteCount DESC ");
            }
            else
            {
                strSelect.AppendFormat(" order by TCreateTS DESC ");
            }
            return dt = SqlUtil.ExecuteDataSet(CommandType.Text, strSelect.ToString()).Tables[0];
        }
        //获取单个Tee数据
        public static DataTable getTeeInfoById(int TeeID)
        {
            StringBuilder strSelect = new StringBuilder();
            strSelect.AppendFormat("select * from v_TeeInfo te where te.TStatus=4 and te.TID={0}", TeeID);
            DataSet ds = new DataSet();
            return SqlUtil.ExecuteDataSet(CommandType.Text, strSelect.ToString()).Tables[0];
        }

        /// <summary>
        /// 设置作品TEE分类
        /// </summary>
        /// <param name="teeID"></param>
        /// <param name="categoryID"></param>
        /// <returns></returns>
        public static bool SetTeeCategory(int teeID, int categoryID)
        {
            bool bSuccess = false;
            try
            {
                StringBuilder strUpdate = new StringBuilder();
                strUpdate.AppendFormat("Update tbteeinfo set tcid={0},tupdatets='{1}' where tid={2}", categoryID, DateTime.Now, teeID);
                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "|method:SetTeeCategory,update sql is " + strUpdate.ToString());
                int iCount = SqlUtil.ExecteNonQuery(CommandType.Text, strUpdate.ToString());
                bSuccess = iCount == 1 ? true : false;
            }
            catch (Exception ex)
            {
                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "|method:SetTeeCategory,error=>" + ex.Message);
            }
            return bSuccess;
        }
        //设置TEE作品状态
        public static bool setTeeStatusById(int teeID, int type, int status)
        {
            bool bSuccess = false;
            try
            {
                StringBuilder strUpdate = new StringBuilder();
                strUpdate.AppendFormat("update tbTeeInfo ");
                switch (type)
                {
                    case 1://入围
                        strUpdate.AppendFormat("set TJoin={0}", status);
                        break;
                    case 2://最潮
                        strUpdate.AppendFormat("set TFashion={0}", status);
                        break;
                    case 3://获奖
                        strUpdate.AppendFormat("set TWin={0}", status);
                        break;
                    case 4://审核
                        strUpdate.AppendFormat("set TStatus={0}", status);
                        break;
                    default:
                        strUpdate.AppendFormat("set TStatus={0}", status);
                        break;
                }

                strUpdate.AppendFormat(" where tid={0}", teeID);
                int iUpdate = SqlUtil.ExecteNonQuery(CommandType.Text, strUpdate.ToString());
                return bSuccess = iUpdate == 1 ? true : false;
            }
            catch (Exception ex)
            {
                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "=>setTeeStatusById" + ex.Message);
                throw;
            }
        }

        //更新作品图片URL地址
        public static bool updateTeeImgUrl(int teeID, string imgUrl)
        {
            bool isSuccess = false;
            StringBuilder strUpdate = new StringBuilder();
            strUpdate.AppendFormat("update tbTEEInfo set ");
            strUpdate.AppendFormat("TPhotoPath={0},TUpdateTS={1}", imgUrl, DateTime.Now);
            strUpdate.AppendFormat(" where tid={0}", teeID);

            int iUpdate = SqlUtil.ExecteNonQuery(CommandType.Text, strUpdate.ToString());
            isSuccess = iUpdate == 1 ? true : false;
            return isSuccess;
        }
        /// <summary>
        /// 后台更新投票数,无用户IP.
        /// </summary>
        /// <param name="tid"></param>
        /// <param name="voteCount"></param>
        /// <returns></returns>
        public static bool SetVoteCountById(int tid, int voteCount)
        {
            bool isSuccess = false;

            #region 获取当前TEE的投票数
            int currentVoteCount = 0;
            StringBuilder strSelect = new StringBuilder();
            strSelect.AppendFormat("select TAVoteCount from v_TeeInfo where ");
            strSelect.AppendFormat("TID={0} and TStatus=4 ", tid);

            object obj = SqlUtil.ExecuteScalar(CommandType.Text, strSelect.ToString());
            if (null != obj && !Convert.IsDBNull(obj))
            {
                currentVoteCount = (int)obj;
                LogUtil.GetInstance().WriteDebugLog("method:set vote, get votecount=>" + currentVoteCount);
            }
            #endregion

            #region 处理用户附属表投票数

            if (currentVoteCount > 0)//如果已有投票数,则更新
            {
                StringBuilder strupdate = new StringBuilder();
                strupdate.AppendFormat("update tbteeattach set ");
                strupdate.AppendFormat("tavotecount={0}", voteCount);
                strupdate.AppendFormat(" where tid={0}", tid);
                int iupdate = SqlUtil.ExecteNonQuery(CommandType.Text, strupdate.ToString());
                if (iupdate == 1)
                {
                    isSuccess = true;
                }
            }
            else//用户第一次投票,保存记录到附属表
            {
                StringBuilder strIns = new StringBuilder();
                strIns.AppendFormat("insert into tbTEEAttach(TID,TAVoteCount,TCreateTS,TUID,TUpdateTS,TStatus) ");
                strIns.AppendFormat("values('{0}','{1}','{2}',", tid, voteCount, DateTime.Now);
                strIns.AppendFormat("'{0}','{1}','{2}')", 0, DateTime.Now, 0);

                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "setVoteCountByIds->insert tbTEEAttach sql is " + strIns.ToString());
                int taID = SqlUtil.ExecteNonQuery(CommandType.Text, strIns.ToString());
                if (taID == 1)
                {
                    isSuccess = true;
                }
            }
            #endregion

            return isSuccess;
        }

        //设置投票数
        public static int setVoteCountByIds(int teeID, string userIP)
        {
            int iFlag = -1;
            try
            {
                if (teeID > 0 && !string.IsNullOrEmpty(userIP))
                {
                    StringBuilder strFashion = new StringBuilder();
                    strFashion.AppendFormat("select tfashion from v_teeinfo where tid={0} and tstatus=4 ", teeID);

                    object objFashion = SqlUtil.ExecuteScalar(CommandType.Text, strFashion.ToString());
                    if (null != objFashion && !Convert.IsDBNull(objFashion) && (int)objFashion != 2)
                    {
                        #region 获取当前TEE的投票数
                        int currentVoteCount = 0;
                        StringBuilder strSelect = new StringBuilder();
                        strSelect.AppendFormat("select TAVoteCount from v_TeeInfo where ");
                        strSelect.AppendFormat("TID={0} and TStatus=4 ", teeID);

                        object obj = SqlUtil.ExecuteScalar(CommandType.Text, strSelect.ToString());
                        if (null != obj && !Convert.IsDBNull(obj))
                        {
                            currentVoteCount = (int)obj;
                            LogUtil.GetInstance().WriteDebugLog("method:set vote, get votecount=>" + currentVoteCount);
                        }
                        #endregion

                        #region 检查用户IP表的投票次数
                        StringBuilder strSelectIP = new StringBuilder();
                        strSelectIP.AppendFormat("select VoteCount from tbTeeUserIP where teeid={0} and ip='{1}' ", teeID, userIP);
                        object objIpCount = SqlUtil.ExecuteScalar(CommandType.Text, strSelectIP.ToString());
                        if (null != objIpCount && !Convert.IsDBNull(objIpCount))
                        {
                            LogUtil.GetInstance().WriteDebugLog("method:setvote, ip table's votecount=>" + objIpCount);

                            if ((int)objIpCount >= 10)
                            {
                                return iFlag = -2;//超过10次投票
                            }
                            else if (null != objIpCount && (int)objIpCount > 0)//用户第n次(N>1)投票
                            {
                                StringBuilder strUpdateUserIP = new StringBuilder();
                                strUpdateUserIP.AppendFormat("update tbTeeUserIP set votecount={0} ", Convert.ToInt32((int)objIpCount + 1));
                                strUpdateUserIP.AppendFormat("where teeid={0} and ip='{1}'", teeID, userIP);
                                int iUpdateVoteCount = SqlUtil.ExecteNonQuery(CommandType.Text, strUpdateUserIP.ToString());
                            }
                        }
                        else
                        {
                            //用户第一次投票
                            StringBuilder strInsertIP = new StringBuilder();
                            strInsertIP.AppendFormat("insert into tbTeeUserIP(ip,votecount,createts,st_valid,teeid)");
                            strInsertIP.AppendFormat("values('{0}','{1}','{2}','{3}',{4})", userIP, 1, DateTime.Now, 0, teeID);
                            LogUtil.GetInstance().WriteDebugLog("insert IP sql=>" + strInsertIP.ToString());
                            int insertUserIP = SqlUtil.ExecteNonQuery(CommandType.Text, strInsertIP.ToString());
                        }
                        #endregion

                        #region 处理用户附属表投票数

                        if (currentVoteCount > 0)//如果已有投票数,则更新
                        {
                            StringBuilder strupdate = new StringBuilder();
                            strupdate.AppendFormat("update tbteeattach set ");
                            strupdate.AppendFormat("tavotecount={0}", currentVoteCount + 1);
                            strupdate.AppendFormat(" where tid={0}", teeID);
                            int iupdate = SqlUtil.ExecteNonQuery(CommandType.Text, strupdate.ToString());
                            if (iupdate == 1)
                            {
                                iFlag = 1;
                            }
                        }
                        else //用户第一次投票,保存记录到附属表
                        {
                            string strSelectTA = string.Format("select tavotecount from tbteeattach where tid={0}", teeID);
                            object iTaVotecount = SqlUtil.ExecuteScalar(CommandType.Text, strSelectTA);
                            if (null != iTaVotecount && !Convert.IsDBNull(iTaVotecount))
                            {
                                StringBuilder strupdateTA = new StringBuilder();
                                strupdateTA.AppendFormat("update tbteeattach set ");
                                strupdateTA.AppendFormat("tavotecount={0}", currentVoteCount + 1);
                                strupdateTA.AppendFormat(" where tid={0}", teeID);
                                int iupdateTA = SqlUtil.ExecteNonQuery(CommandType.Text, strupdateTA.ToString());
                                if (iupdateTA == 1)
                                {
                                    iFlag = 1;
                                }
                            }
                            else
                            {
                                StringBuilder strIns = new StringBuilder();
                                strIns.AppendFormat("insert into tbTEEAttach(TID,TAVoteCount,TCreateTS,TUID,TUpdateTS,TStatus) ");
                                strIns.AppendFormat("values('{0}','{1}','{2}',", teeID, 1, DateTime.Now);
                                strIns.AppendFormat("'{0}','{1}','{2}')", 0, DateTime.Now, 0);

                                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "setVoteCountByIds->insert tbTEEAttach sql is " + strIns.ToString());
                                int taID = SqlUtil.ExecteNonQuery(CommandType.Text, strIns.ToString());
                                if (taID == 1)
                                {
                                    iFlag = 1;
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        iFlag = -3;//投票功能已锁定,已经是获奖作品
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "|method:setVoteCountByIds=>" + ex.Message);
            }
            return iFlag;
        }

        //检索关键词
        public static DataTable searchTeeByKeyword(string query)
        {
            StringBuilder strSelect = new StringBuilder();
            strSelect.AppendFormat("select * from (");

            strSelect.AppendFormat("select top 90 * from v_TeeInfo  ");
            strSelect.AppendFormat("where tname like '%{0}%' or tauthor like '%{0}%' ", query.Trim());

            strSelect.AppendFormat(") t where t.tstatus=4;");

            DataTable dt = SqlUtil.ExecuteDataSet(CommandType.Text, strSelect.ToString()).Tables[0];
            return dt;
        }
        //获取分类作品TEE
        public static DataTable searchTeeByOrder(int teeStatus)
        {
            if (teeStatus == 7)//当搜索请求为7时，意味组合检索名人TEE与艺术家TEE
            {
                StringBuilder strStart = new StringBuilder();
                strStart.AppendFormat("select top 90 * from (select * from v_teeinfo where tcid=4 or tcid=5 )tb ");
                strStart.AppendFormat(" where tstatus!=-1 order by tcreatets desc; ");

                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "->method:searchTeeByOrder,teeStatus=7,the sql is=>" + strStart.ToString());

                return SqlUtil.ExecuteDataSet(CommandType.Text, strStart.ToString()).Tables[0];
            }
            else
            {
                StringBuilder strBuilder = new StringBuilder();
                if (teeStatus == 1)
                {
                    strBuilder.AppendFormat("select top 90 * from (select * from v_teeinfo where tfashion!=2 ) tb");

                    strBuilder.AppendFormat(" order by tavotecount desc ");
                }
                else
                {
                    strBuilder.AppendFormat("select top 90 * from v_teeinfo ti where ti.TStatus=4 ");

                    strBuilder.AppendFormat("and ti.TCID={0} ", teeStatus);
                    strBuilder.AppendFormat(" order by tcreatets desc ");
                }
                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "->method:searchTeeByOrder,the sql is=>" + strBuilder.ToString());

                return SqlUtil.ExecuteDataSet(CommandType.Text, strBuilder.ToString()).Tables[0];
            }
        }
        /// <summary>
        /// 综合检索作品TEE信息
        /// </summary>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="source"></param>
        /// <param name="status"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        public static DataTable GetTeeListBySearch(string Mobile, string startTime, string endTime, int source,
            int status, int category, string teeName, int pageIndex, int pageSize, out int totalCount)
        {
            totalCount = 0;
            DataTable dtTeeLis = new DataTable();
            StringBuilder strSelect = new StringBuilder();
            try
            {
                if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime))
                {
                    strSelect.AppendFormat("TCreateTs between '{0}' and '{1}' ", startTime + " 00:00:00", endTime + " 23:59:59");
                }
                if (status != 0 && status != 4)
                {
                    switch (status)
                    {
                        case 1:
                            strSelect.AppendFormat("and TJoin={0} ", status);
                            break;
                        case 2:
                            strSelect.AppendFormat("and TFashion={0} ", status);
                            break;
                        case 3:
                            strSelect.AppendFormat("and TWin={0} ", status);
                            break;
                    }

                }
                if (status == 4)
                {
                    strSelect.AppendFormat("and TStatus=0 ");
                }
                else
                {
                    strSelect.AppendFormat("and TStatus!=-1 ");
                }
                if (source != 0)
                    strSelect.AppendFormat("and TSource={0} ", source);

                if (category != 0 && category != 1)//排除最热的作品,最热门是个排序方式
                {
                    strSelect.AppendFormat("and TCID={0} ", category);
                }

                if (!string.IsNullOrEmpty(teeName))
                    strSelect.AppendFormat("and tauthor like '%{0}%' ", teeName);
                if (!string.IsNullOrEmpty(Mobile))
                {
                    strSelect.AppendFormat("and tmobile='{0}'", Mobile);
                }
                string strOrderBy = category == 1 ? "tavotecount desc " : "tupdatets DESC";

                SqlParameter[] sqlParam = new SqlParameter[]{
                   new SqlParameter("@TableName","v_teeinfo "),
                   new SqlParameter("@FieldList","*"),
                   new SqlParameter("@PrimaryKey","tid"),
                   new SqlParameter("@Where",strSelect.ToString ()),
                   new SqlParameter("@Order",strOrderBy),
                   new SqlParameter("@SortType","3"),
                   new SqlParameter("@RecorderCount","0"),
                   new SqlParameter("@PageIndex",pageIndex),
                   new SqlParameter("@PageSize",pageSize),
                   new SqlParameter("@TotalCount",SqlDbType.Int),
                   new SqlParameter("@TotalPageCount",SqlDbType.Int)
                };
                sqlParam[9].Direction = ParameterDirection.Output;
                sqlParam[10].Direction = ParameterDirection.Output;
                dtTeeLis = SqlUtil.ExecuteDataSet(CommandType.StoredProcedure, "P_viewPage", sqlParam).Tables[0];
                totalCount = (int)sqlParam[9].Value;
            }
            catch (Exception ex)
            {
                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "=>method:GetTeeListBySearch;error=>" + ex.Message);
            }
            return dtTeeLis;

        }
        //根据时间进行检索
        public static DataTable GetTeeListByTime(string startTime, string endTime)
        {
            StringBuilder strSelectTime = new StringBuilder();
            try
            {
                strSelectTime.AppendFormat("select top 100 * from v_teeinfo ");
                strSelectTime.AppendFormat("where tstatus!=-1 and ");
                strSelectTime.AppendFormat(" tcreatets between '{0}' and '{1}' ", startTime + " 00:00:00 ", endTime + " 23:59:59 ");
                return SqlUtil.ExecuteDataSet(CommandType.Text, strSelectTime.ToString()).Tables[0];
            }
            catch (Exception ex)
            {
                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "=>GetTeeListByTime=>" + ex.Message);
                throw;
            }
        }

        //根据分类ID获取Tee列表
        public static DataTable getTeeListByCID(int categoryID)
        {
            StringBuilder strSelect = new StringBuilder();
            strSelect.AppendFormat("select top 100 * from v_TeeInfo where TStatus=4 ");
            if (categoryID != 0)
                strSelect.AppendFormat("and TSource={0}", categoryID);
            strSelect.AppendFormat(" order by TCreateTS DESC;");
            DataTable dt = SqlUtil.ExecuteDataSet(CommandType.Text, strSelect.ToString()).Tables[0];
            return dt;
        }

        //获取每天入围的20部作品
        public static DataTable getTop20ByDay(string day)
        {
            StringBuilder strTop20 = new StringBuilder();
            DateTime startTime = DateTime.Parse(day + " 00:00:00");
            DateTime endTime = DateTime.Parse(day + " 23:59:59");

            strTop20.AppendFormat("select top 20 * from v_TeeInfo ");
            strTop20.AppendFormat("where TJoin=1 and ");
            strTop20.AppendFormat("TCreateTS between '{0}' ", startTime);
            strTop20.AppendFormat("and '{0}' ", endTime);
            strTop20.AppendFormat("order by TCreateTS desc");
            DataTable dt = SqlUtil.ExecuteDataSet(CommandType.Text, strTop20.ToString()).Tables[0];
            return dt;
        }

        //获取每月入围的6部作品
        public static DataTable getTop6ByMonth(string month)
        {
            string year = month.Substring(0, 4) + "-";
            string tempMonth = month.Substring(5, 2) + "-15";
            string nextMonth = "0" + Convert.ToInt32(Convert.ToInt32(tempMonth.Substring(1, 1)) + 1).ToString() + "-15";

            string startMonth = year + tempMonth + " 00:00:00";
            string endMonth = year + nextMonth + " 23:59:59";

            DataTable dt = new DataTable();
            StringBuilder strTop20 = new StringBuilder();
            strTop20.AppendFormat("select top 6 * from v_TeeInfo ");
            strTop20.AppendFormat("where TFashion=2 and ");
            strTop20.AppendFormat("TCreateTS between '{0}' ", startMonth);
            strTop20.AppendFormat("and '{0}' ", endMonth);
            strTop20.AppendFormat("order by TCreateTS desc");
            try
            {
                dt = SqlUtil.ExecuteDataSet(CommandType.Text, strTop20.ToString()).Tables[0];
            }
            catch (Exception ex)
            {
                LogUtil.GetInstance().WriteDebugLog("getTop6ByMonth,error->" + ex.Message);
                throw;
            }
            return dt;
        }
        //get total count for teeinfo
        public static int getTeeTotalCount()
        {
            StringBuilder strSelect = new StringBuilder();
            int iTotalCount = 0;
            strSelect.AppendFormat("select count(*) from v_teeinfo ");
            strSelect.AppendFormat("where TStatus!=-1 ");

            object obj = SqlUtil.ExecuteScalar(CommandType.Text, strSelect.ToString());
            if (null != obj)
            {
                iTotalCount = (int)obj;
            }
            return iTotalCount;
        }

        //分页获取TeeList
        public static DataTable getTeeListByPage(int pageIndex, int pageSize, string orderType, out int rowCount)
        {
            rowCount = 0;
            string strOrder = string.Empty;
            if (!string.IsNullOrEmpty(orderType))
            {
                strOrder = "TAvoteCount DESC ";
            }
            else
            {
                strOrder = "TCreateTS DESC ";
            }
            string strWhere = "TStatus=4 ";

            DataTable dt = new DataTable();
            SqlParameter[] sqlParam = new SqlParameter[]{
                   new SqlParameter("@TableName","v_teeinfo "),
                   new SqlParameter("@FieldList","*"),
                   new SqlParameter("@PrimaryKey","tid"),
                   new SqlParameter("@Where",strWhere),
                   new SqlParameter("@Order",strOrder),
                   new SqlParameter("@SortType","3"),
                   new SqlParameter("@RecorderCount","0"),
                   new SqlParameter("@PageIndex",pageIndex),
                   new SqlParameter("@PageSize",pageSize),
                   new SqlParameter("@TotalCount",SqlDbType.Int),
                   new SqlParameter("@TotalPageCount",SqlDbType.Int)
                };
            sqlParam[9].Direction = ParameterDirection.Output;
            sqlParam[10].Direction = ParameterDirection.Output;
            dt = SqlUtil.ExecuteDataSet(CommandType.StoredProcedure, "P_viewPage", sqlParam).Tables[0];
            rowCount = (int)sqlParam[9].Value;
            return dt;
        }

        //新增Tee数据
        public static int addTeeInfo(string Name, string Author,
            string Address, string VideoPath, string Email, string Mobile, string Intro,
           string strSmallPath, string strMiddPath, string strLargePath, int Status, string Source,
            int UserID, string PhotoName, string PhotoPath, out int teeID)
        {
            teeID = 0;
            int iCount = 0;
            try
            {
                string strSelect = string.Format("select 1 from tbTEEInfo te where te.TName='{0}' and te.TAuthor='{1}'", Name, Author);
                object obj = SqlUtil.ExecuteScalar(CommandType.Text, strSelect);

                if (null != obj && Convert.ToInt32(obj) == 1)
                {
                    iCount = -2;
                }
                else
                {
                    StringBuilder strInsert = new StringBuilder();
                    strInsert.AppendFormat("insert into tbTEEInfo ( ");
                    strInsert.AppendFormat("tbTEEInfo.TName,tbTEEInfo.TAuthor,tbTEEInfo.TEmail,tbTEEInfo.TMobile,");
                    strInsert.AppendFormat("tbTEEInfo.TAddress,tbTEEInfo.TSource,tbTEEInfo.TIntro,tbTEEInfo.TVideo,");
                    strInsert.AppendFormat("tbTEEInfo.TPhotoPath,tbTEEInfo.TPhotoName,tbTEEInfo.TSmallImage,");
                    strInsert.AppendFormat("tbTEEInfo.TMiddImage,tbTEEInfo.TLargeImage,tbTEEInfo.TCreateTS,");
                    strInsert.AppendFormat("tbTEEInfo.TUpdateTS,tbTEEInfo.TUID,tbTEEInfo.TCID,tbTEEInfo.TStatus) ");
                    strInsert.AppendFormat("values(");
                    strInsert.AppendFormat("'{0}','{1}','{2}','{3}',", Name, Author, Email, Mobile);
                    strInsert.AppendFormat("'{0}',{1},'{2}','{3}','{4}',", Address, TEEUtil.AnaylsisTeeSource(Source), Intro, VideoPath, PhotoPath);
                    strInsert.AppendFormat("'{0}','{1}','{2}','{3}',", PhotoName, strSmallPath, strMiddPath, strLargePath);
                    strInsert.AppendFormat("'{0}','{1}',{2},{3},{4}); select @@IDENTITY;", DateTime.Now, DateTime.Now, UserID, 0, Status);


                    object iInsert = SqlUtil.ExecuteScalar(CommandType.Text, strInsert.ToString());
                    if (null != iInsert)
                    {
                        teeID = Convert.ToInt32(iInsert);
                        iCount = 1;
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.GetInstance().WriteDebugLog(DateTime.Now.ToString() + "method:addTeeInfo=>" + ex.Message);
            }
            return iCount;
        }
    }
}
